package me.itsoo.artemis.framework.repository.datasource;

import java.sql.Connection;

/**
 * SqlConnectionProxyFactory
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/19
 */
public class SqlConnectionProxyFactory {

    private final ConnectionPool dataSource;

    public SqlConnectionProxyFactory(ConnectionPool dataSource) {
        this.dataSource = dataSource;
    }

    /**
     * 创建 SqlConnection
     *
     * @param connection Connection
     * @return SqlConnection
     */
    public SqlConnection getSqlConnection(Connection connection) {
        return wrap(connection);
    }

    /**
     * 包装 SqlConnection
     *
     * @param connection Connection
     * @return SqlConnection
     */
    private SqlConnection wrap(Connection connection) {
        return new SqlConnectionProxy(dataSource, connection);
    }
}
